import 'package:flutter/material.dart';
import 'package:flutter_app/main/main/main_child.dart';
import 'package:flutter_app/main/square/widget/square.dart';

class MainWidget extends StatefulWidget {
  const MainWidget({super.key});

  @override
  MainPageWidget createState() => MainPageWidget();
}

class MainPageWidget extends State<MainWidget> {
  @override
  Widget build(BuildContext context) {

    PageController controller = PageController(
      initialPage: 1,       //用来配置PageView中默认显示的页面 从0开始
      keepPage: true,       //为true是保持加载的每个页面的状态
    );

    controller.addListener(() {
      double? page = controller.page;
    });

    return Container(
      color: Colors.white,
      width: double.infinity,
      height: double.infinity,
      child: PageView(
        scrollDirection: Axis.horizontal,
        allowImplicitScrolling: true,
        pageSnapping: true,
        controller: controller,
        children: const [
          SquareWidget(),
          MainChildWidget()
        ],
      ),
    );
  }
}